<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-11-17 10:09:31
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-11-23 14:48:10
 * @FilePath: /hgpt-admin/src/pages/login/index.vue
 * @Description: 文件介绍
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <div class="loginView">
    <div class="inputCard">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>健康管理后台</span>
        </div>
        <div class="mainBox">
          <el-form :model="loginform" ref="loginform" :rules="loginRules">
            <el-form-item prop="name" class="userInput">
              <el-input
                v-model="loginform.name"
                placeholder="请输入用户名"
                prefix-icon="el-icon-user-solid"
                type="text"
              ></el-input>
            </el-form-item>
            <el-form-item prop="pass" class="passWordInput">
              <el-input
                placeholder="请输入密码"
                v-model="loginform.pass"
                show-password
                prefix-icon="el-icon-lock"
                type="password"
              ></el-input>
            </el-form-item>
          </el-form>
          <el-button class="loginBtn" type="primary" @click="login" round
            >登录</el-button
          >
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
// import { setCookie } from "../../tools/Cookie";
export default {
  data () {
    return {
      loginform: {
        name: "",
        pass: "",
      },
      loginRules: {
        name: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        pass: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    }
  },
  mounted () {

  },
  methods: {
    // 登陆
    login () {
      this.$refs["loginform"].validate((valid) => {
        if (valid) {
          this.$api.post('rest/doLogin?password=' + this.loginform.pass + '&username=' + this.loginform.name, {
          }).then(res => {
            console.log(res)
            if (res.statusCode == '200') {
              sessionStorage.setItem("token", res.result.tokenValue)
              sessionStorage.setItem("userInfo", JSON.stringify({userName: this.loginform.name}))
              this.$router.push({ name: "reservationSearch" })
              // setCookie("token", res.result.tokenValue)
              this.$message.success("登陆成功")
            } else {
              this.$message.error(res.message||"登陆失败")
            }
          })
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.loginView {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  .inputCard {
    width: 500px;
  }
}
</style>>

